import request from '@/config/axios'

// 简历信息 VO
export interface ResumeInfoVO {
  id: number // 简历编号
  resumeName: string // 简历名
  resumePath: string // pdf路径
  userId: number // FK用户id
}

export interface FilePageReqVO extends PageParam {
  path?: string
  type?: string
  createTime?: Date[]
}

// 简历信息 API
export const ResumeInfoApi = {
  // 查询简历信息分页
  getResumeInfoPage: async (params: any) => {
    return await request.get({ url: `/dbit/resume-info/page`, params })
  },

  // 查询简历信息详情
  getResumeInfo: async (id: number) => {
    return await request.get({ url: `/dbit/resume-info/get?id=` + id })
  },

  // 新增简历信息
  createResumeInfo: async (data: ResumeInfoVO) => {
    return await request.upload({ url: `/dbit/resume-info/create`, data})
  },

  // 修改简历信息
  updateResumeInfo: async (data: ResumeInfoVO) => {
    return await request.put({ url: `/dbit/resume-info/update`, data })
  },

  // 删除简历信息
  deleteResumeInfo: async (id: number) => {
    return await request.delete({ url: `/dbit/resume-info/delete?id=` + id })
  },

  // 导出简历信息 Excel
  exportResumeInfo: async (params) => {
    return await request.download({ url: `/dbit/resume-info/export-excel`, params })
  }
}

// 文件预签名地址 Response VO
export interface FilePresignedUrlRespVO {
  // 文件配置编号
  configId: number
  // 文件上传 URL
  uploadUrl: string
  // 文件 URL
  url: string
}

// 查询文件列表
export const getFilePage = (params: FilePageReqVO) => {
  return request.get({ url: '/infra/file/page', params })
}

// 删除文件
export const deleteFile = (id: number) => {
  return request.delete({ url: '/infra/file/delete?id=' + id })
}

// 获取文件预签名地址
export const getFilePresignedUrl = (path: string) => {
  return request.get<FilePresignedUrlRespVO>({
    url: '/infra/file/presigned-url',
    params: { path }
  })
}

// 创建文件
export const createFile = (data: any) => {
  return request.post({ url: '/infra/file/create', data })
}

// 上传文件
export const updateFile = (data: any) => {
  return request.upload({ url: '/dbit/resume-info/create', data })
}
